home *** CD-ROM | disk | FTP | other *** search
- Path: thor.tu.hac.com!collins
- From: collins@thor.tu.hac.com (Ron Collins)
- Newsgroups: comp.lang.c
- Subject: Re: Array Parameters
- Date: 3 Jan 1996 14:16:41 GMT
- Organization: Advanced Depot Systems
- Message-ID: <4ce349$4j9@hacgate2.hac.com>
- References: <wayne.820650643@hawk>
- NNTP-Posting-Host: thor.tu.hac.com
-
- Wayne Elliott (wayne@adied.oz.au) wrote:
- : Can anyone fill me in on whats wrong with the following snippet of
- : code. Basically I'm trying to pass and use a multi-dimensional
- : array.
-
- : -----------------------------------------------------------------
-
- : /* Test passing of array parameters */
-
- : #include <stdio.h>
-
- : char map [][8] =
- ^^^^^^^^^^^^^^^^
-
- Change this to
-
- char *map[] =
- : {
- : "abcdef",
- : "ghijkl",
- : "mnopqr"
- : };
-
- : void test(int num, char ** maps)
- ^^^^^^^^^^^^
-
- Change this to
-
- void test(int num, char*maps[])
- : {
- : int i;
- : for(i=0;i<num;i++)
- : if(maps[i])
- : printf("%04d %s\n", i, maps[i]);
- : else
- : printf("%04d NULL\n", i);
- : }
-
- : int main()
- : {
- : test(3, (char **) map);
- ^^^^^^^^^
-
- Change this to
-
- test(3, map);
- : return 0;
- : }
-
-
- While there are circumstances where an array may behave as a pointer, they
- are different items with different characteristics and properties. These
- differences become more pronounced with multi-dimensional arrays. I believe
- the FAQ covers this in detail.
-
-
- -- Collins --
-
- -----
- The views expressed here are mine alone.
-
- Ron Collins/Hughes Aircraft Company/M20,P20/Tucson Az 85706
- rcollins@thor.tu.hac.com collins@seagull.rtd.com
- ยก----
-